#include <stdio.h>
#include <stdlib.h>

  typedef  struct {
        char name [10];
        int num;
        int age;
        char addr [30];
    } STU; 

int main(){
    
    STU stu;
 
    FILE * output  = fopen("stud.dat","w+");//生成的stud.dat文件无法用记事本打开，打开后显示“乱码”。
 
    if(output == NULL){
        printf("无法打开文件");
        exit(0);
    }
 
    for(int i=0;i<10;++i){
        // scanf("%s%d%d%s",,&stud[i].num,&stud[i].age,stud[i].addr);       
        sprintf(stu.name,"RECORE-%d",i);
        stu.num = 100 + i;
        stu.age = 15 + i;
        sprintf(stu.addr," ADDR-%d",i);

        fwrite(&stu,sizeof(stu),1,output);
    }
    fclose(output);

    //读第7条数据
    output = fopen("stud.dat","r+");
    fseek(output,7*sizeof(stu),SEEK_SET);
    fread(&stu,sizeof(stu),1,output);

    printf(" name = %s\n num = %d\n age = %d \n addr = %s \n",stu.name,stu.num,stu.age,stu.addr);
    


    fclose(output);

    return 0;
}